home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / ParentStack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  2.9 KB  |  114 lines

  1. #ifndef _PARENTSTACK_H_
  2. #define _PARENTSTACK_H_
  3. /*
  4.  *   $RCSfile: ParentStack.h,v $  
  5.  *   $Revision: 1.1.1.1 $  
  6.  *   $Date: 1996/05/04 21:55:07 $      
  7.  */ 
  8. /**********************************************************************
  9. * EXODUS Database Toolkit Software
  10. * Copyright (c) 1991 Computer Sciences Department, University of
  11. *                    Wisconsin -- Madison
  12. * All Rights Reserved.
  13. *
  14. * Permission to use, copy, modify and distribute this software and its
  15. * documentation is hereby granted, provided that both the copyright
  16. * notice and this permission notice appear in all copies of the
  17. * software, derivative works or modified versions, and any portions
  18. * thereof, and that both notices appear in supporting documentation.
  19. *
  20. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  21. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  22. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  23. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  24. *
  25. * The EXODUS Project Group requests users of this software to return 
  26. * any improvements or extensions that they make to:
  27. *
  28. *   EXODUS Project Group 
  29. *     c/o David J. DeWitt and Michael J. Carey
  30. *   Computer Sciences Department
  31. *   University of Wisconsin -- Madison
  32. *   Madison, WI 53706
  33. *
  34. *     or exodus@cs.wisc.edu
  35. *
  36. * In addition, the EXODUS Project Group requests that users grant the 
  37. * Computer Sciences Department rights to redistribute these changes.
  38. **********************************************************************/
  39. #ifndef PARENTSTACK_H
  40. #define PARENTSTACK_H
  41.  
  42. class ParentStack  {
  43.         int         cnt;                    // # of valid entries in descPtr[]
  44.         BUFGROUP*    bufGroup;                // buffer group associated w. stack
  45.         PageDesc    descPtr[MAXPARENTS];    // pages in stack
  46.     public:
  47.         ParentStack(BUFGROUP* bg)    { cnt = 0; bufGroup = bg; }
  48.         ~ParentStack();
  49.         
  50.         //
  51.         //    Read page 'pid' in 'lockMode' and push it onto the stack
  52.         //
  53.         ReadNPush(const PID& pid, LOCKMODE lm);
  54.         
  55.         //
  56.         //    Unlock/Unfix all entries except top of stack
  57.         //
  58.         void
  59.         ReleaseAllPrevious()    { 
  60.                         for (int i = cnt-2; i>= 0; i--)  {
  61.                             if ((GROUPLINK*)descPtr[i])
  62.                                 descPtr[i].UnfixUnlock();
  63.                             }
  64.                         }
  65.         
  66.         //
  67.         //    Unlock/Unfix the entry before top of stack
  68.         //
  69.         void
  70.         ReleasePrevious()         { 
  71.                         if (cnt>1 && (GROUPLINK*) descPtr[cnt-2])
  72.                         descPtr[cnt-2].UnfixUnlock();
  73.                         }
  74.                                 
  75.  
  76.         //
  77.         //    Push/Pop a page to/from stack
  78.         //
  79.         PageDesc
  80.         Pop()            { ASSERT1(cnt > 0); return descPtr[--cnt]; }
  81.  
  82.         void
  83.         Push(PageDesc pd)    {
  84.                         ASSERT1(cnt < MAXPARENTS-1); 
  85.                         descPtr[cnt++] = pd; 
  86.                         }
  87.  
  88.         //
  89.         //    Pop a page and unfix/unlock it
  90.         //
  91.         void
  92.         DiscardTop();
  93.  
  94.         //
  95.         //    Return a reference to the stack top
  96.         //
  97.         PageDesc&
  98.         Top()            { ASSERT1(cnt > 0); return descPtr[cnt-1]; }
  99.  
  100.         //
  101.         //    Return current stack size
  102.         //
  103.         NumEntries()    { return cnt; }
  104.         
  105.         //
  106.         //    Print the stack (for debugging)
  107.         //
  108.         void 
  109.         Print();
  110.         };
  111.  
  112. #endif // PARENTSTACK_H
  113. #endif /* _PARENTSTACK_H_ */
  114.